import logging,datetime,os

# 控制日志的最低输出级别
LogLv = 0
LogLvList = [logging.DEBUG,logging.INFO,logging.WARNING,logging.ERROR,logging.CRITICAL]
logging.basicConfig(format=f'[%(levelname)s] [%(name)s]%(asctime)s:>>> %(message)s',
                    level=LogLvList[LogLv])

def print_debug(msg,*args,indent=","):
    msg = str(msg)
    for i in args:
        msg += f"{indent}{i}"
    logging.debug(msg)

def print_info(msg,*args,indent=","):
    msg = str(msg)
    for i in args:
        msg += f"{indent}{i}"
    logging.info(msg)

def print_waring(msg,*args,indent=","):
    msg = str(msg)
    for i in args:
        msg += f"{indent}{i}"
    logging.warning(msg)

def print_error(msg,*args,indent=","):
    msg = str(msg)
    for i in args:
        msg += f"{indent}{i}"
    # error级别的日志写入文件
    utc_now = datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc)
    obj = utc_now.astimezone(datetime.timezone(datetime.timedelta(hours=8)))
    timeStr = datetime.datetime(obj.year, obj.month, obj.day, obj.hour, obj.minute, obj.second)
    
    if not os.path.exists("logs"):
        os.system("mkdir logs")
    with open(f"logs/错误日志-{str(timeStr).split(' ')[0]}.log","a+",encoding="utf-8") as f:
        info = f"[{str(timeStr)}] [ERROR]:  {msg}\n"
        f.write(info)
    logging.error(msg)

def print_critical(msg,*args,indent=","):
    msg = str(msg)
    for i in args:
        msg += f"{indent}{i}"
    logging.critical(msg)